﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/HomeSite.Master" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>

<%@ Register Assembly="DevExpress.Web.v11.1, Version=11.1.7.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a"
    Namespace="DevExpress.Web.ASPxRoundPanel" TagPrefix="dx" %>

<%@ Register assembly="DevExpress.Web.v11.1, Version=11.1.7.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" namespace="DevExpress.Web.ASPxPanel" tagprefix="dx" %>
<%--Neu gap duong dan Management/CreateMultiUser?filename=abc1.xls thi kiem tra xem filename con ton tai tap tin do tren server hay khong.
Neu khong ton tai thi hien thong bao loi--%>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
<div id="dialog" title="Upload files">
        <% using (Html.BeginForm("Upload", "File", FormMethod.Post, new { enctype = "multipart/form-data", onsubmit = "return checkfile()" })) 
           {%>
            <p><input type="file" id="fileUpload" name="fileUpload" size="53" onchange="checkfileexist(this)"/> </p>
            <input id="control" name="control" type="hidden" value="Student" />
            <input id="action" name="action" type="hidden" value="Import" />
            <p><input type="submit" value="Upload file" /></p>
            <%-- Trung them JavaScript o day --%>
            <% 
               //Getting the current context of HTTP request
               var context = HttpContext.Current;
               //Formatting the fully qualified website url/name
               var appPath = string.Format("{0}://{1}{2}{3}",
                                           context.Request.Url.Scheme,
                                           context.Request.Url.Host,
                                           context.Request.Url.Port == 80
                                               ? string.Empty
                                               : ":" + context.Request.Url.Port,
                                           context.Request.ApplicationPath);

               if (!appPath.EndsWith("/"))
                   appPath += "/";
               
                
                 %>
            <script type="text/javascript">
                function checkfile() {
                    $file = document.getElementById('fileUpload').value.trim();
                    if ((($file.lastIndexOf('.xls') - $file.length) >= -5) && ($file.lastIndexOf('.xls') != -1)) {

                        return true;
                    }
                    alert("Ðịnh dạng tệp không chính xác");
                    return false;
                }
            </script>
            <script>
                function checkfileexist(inputbutton) {
                    if (inputbutton.value == "") return;
                    $path = "<%: appPath  %>Management/CreateMultiUser?filename=" + inputbutton.value + "&mode=check";
                    $.ajax({
                        type: 'POST',
                        url: $path,
                        context: "",
                        success: function (data) {
                            if (data == "ok") {
                                alert("Chú ý! Tệp hiện tại đã tồn tại trên hệ thống!\n Xin chú ý trước khi tải tệp lên!");
                            }
                        }
                    });
                }
            </script>
            <%--Can mot javascript de kiem tra dinh dang tap tin, bat buoc phai l /a tap tin excel.--%>
        <% } %>
    </div>
    <dx:ASPxRoundPanel ID="ASPxRoundPanel1" runat="server" Width="100%" 
        CssFilePath="~/App_Themes/Aqua/{0}/styles.css" CssPostfix="Aqua" 
        GroupBoxCaptionOffsetY="-28px" HeaderText="Create Mulitple User"
        SpriteCssFilePath="~/App_Themes/Aqua/{0}/sprite.css">
        <ContentPaddings Padding="14px" />
        <PanelCollection>
<dx:PanelContent ID="PanelContent1" runat="server" SupportsDisabledAttribute="True">1. Chuẩn bị file 
    excel theo cấu trúc:<br /> &nbsp;&nbsp;&nbsp; Cột A: Username
    <br />
    &nbsp;&nbsp;&nbsp; Cột B: Displayname<br /> &nbsp;&nbsp;&nbsp; Cột C: Password<br /> &nbsp;&nbsp;&nbsp; Cột D: ID_Role<br /> 
    Xem bảng <a href="/Role"> danh sách các role </a> để biết id_role. Tải về tập tin ví dụ.<br /> 
    2. Bấm <a href="#" onclick="jQuery('#dialog').dialog('open'); return false">Upload File</a> để gửi file lên.<br /> 3. Chương trình sẽ liệt kê các user mà nó 
    đọc được trong file gửi lên.<br /> 4. Xác nhận lại lần nữa.<br /> 5. Hoàn tất.</dx:PanelContent>
</PanelCollection>
    </dx:ASPxRoundPanel>
    <% if (ViewData["kq"].Equals("ok"))
       { %>
       Them thanh cong
   <% } %>
   <% if (ViewData["kq"].Equals("un"))
       { %>
       Them bi loi
   <% } %>
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="HeadContent" runat="server">
    <script type="text/javascript">
        $(function () {
            $("#dialog").dialog({
                bgiframe: true,
                height: 150,
                width: 400,
                modal: true,
                autoOpen: false,
                resizable: false
            })
        });
        
    </script>
</asp:Content>

<asp:Content ID="Content3" ContentPlaceHolderID="leftmenu" runat="server">
</asp:Content>

<asp:Content ID="Content4" ContentPlaceHolderID="menuright" runat="server">
</asp:Content>

<asp:Content ID="Content5" ContentPlaceHolderID="Footer" runat="server">
</asp:Content>
